package com.xwh.b2c.controller;

import com.xwh.b2c.common.Result;
import com.xwh.b2c.dto.AdminLoginDTO;
import com.xwh.b2c.entity.Admin;
import com.xwh.b2c.service.AdminService;
import com.xwh.b2c.vo.AdminInfoVO;
import com.xwh.b2c.vo.AdminLoginVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 管理员用户表 前端控制器
 * </p>
 *
 *
 * @since 2025-07-07
 */
@Slf4j
@RestController
//@CrossOrigin // 解决跨域CORS 不推荐
@Tag(name = "管理员管理")
@RequestMapping("/admin")
public class AdminController {
    @Resource
    private AdminService adminService;

    //TODO 0708 实现管理员后台跟java后端互通
    @PostMapping("login")
    public Result<AdminLoginVO> login(@RequestBody AdminLoginDTO adminLoginDTO){
        log.info("账号:{}",adminLoginDTO.getUsername());
        log.info("密码:{}",adminLoginDTO.getPassword());
        AdminLoginVO adminLoginVO = adminService.login(adminLoginDTO);
        return Result.success(adminLoginVO);
    }

    //TODO 0708 实现管理员后台跟java后端互通
    @PostMapping("info")
    public Result<AdminInfoVO> info(){
        AdminInfoVO adminInfoVO = this.adminService.info();
        return Result.success(adminInfoVO);
    }
}
